import { createRef, useEffect, useRef } from "react";
import { GameCore } from "./game-core";

const GameView: React.FC = () => {
  const div = createRef<HTMLDivElement>();
  const game = useRef<GameCore>(null);

  useEffect(() => {
    if (!game.current) {
      game.current = new GameCore(div.current!);
    }

    return () => {
      game.current?.close();
    };
  }, []);

  return (
    <div className="p-10 h-screen">
      <div ref={div} className="h-full" />
    </div>
  );
};

export default GameView;
